laetitia=# create table test(id integer generated always as identity);
CREATE TABLE
laetitia=# table test;
id
----
(0 rows)
laetitia=# begin;
BEGIN
laetitia=*# drop table test;
DROP TABLE
laetitia=*# table test;
2024-04-11 13:05:20.589 CEST [18422] ERROR: relation "test" does not exist at character 7
2024-04-11 13:05:20.589 CEST [18422] STATEMENT: table test;
ERROR: relation "test" does not exist
LINE 1: table test;
^
laetitia=!# rollback;
ROLLBACK
laetitia=# table test;
id
----
(0 rows)
COMMENT ON LANGUAGE plpython IS 'Python support for stored procedures';
COMMENT ON OPERATOR - (NONE, integer) IS 'Unary minus';
COMMENT ON DATABASE my_database IS 'Development Database';
COMMENT ON ROLE my_role IS 'Administration group for finance tables';
Access ALL YOUR DATA (really, all your data, we are not joking) from EVERYWHERE to Postgres!
laetitia=# create table select (id integer);
ERROR: syntax error at or near "select"
LINE 1: create table select (id integer);
^
laetitia=# create table "select" (id integer);
CREATE TABLE
laetitia=#
select * from "select";
id
----
(0 rows)
laetitia=# select * from select;
ERROR: syntax error at or near "select"
LINE 1: select * from select;
^
laetitia=#
values ("test");
ERROR: column "test" does not exist
LINE 1: values ("test");
^
laetitia=# values ('test');
column1
---------
test
(1 row)
laetitia=#
values (E'They exclaimed, \'There are three different types of quotes:\n
single quotes ( \' ),\n
double quotes ( \" ),\n
and backticks ( \` ).\'');
column1
--------------------------------------------------------------
They exclaimed, 'There are three different types of quotes: +
single quotes ( ' ), +
double quotes ( " ), +
and backticks ( ` ).'
(1 row)
laetitia=# values ('He whispered, ''The password is ''swordfish''.''');
column1
----------------------------------------------
He whispered, 'The password is 'swordfish'.'
(1 row)
laetitia=# values($$They exclaimed, There are three different types of quotes:
single quotes ( ' ),
double quotes ( " ),
and backticks ( ` ).'$$);
column1
------------------------------------------------------------
They exclaimed, There are three different types of quotes:+
single quotes ( ' ), +
double quotes ( " ), +
and backticks ( ` ).'
(1 row)
laetitia=# values (
$Sentence$He whispered, 'The password is 'swordfish'.'$Sentence$);
column1
----------------------------------------------
He whispered, 'The password is 'swordfish'.'
(1 row)
string SIMILAR TO pattern [ESCAPE escape-character]
string NOT SIMILAR TO pattern [ESCAPE escape-character]
'thomas' ~ 't.*ma' → t
'thomas' ~ 'T.*ma' → t
'thomas' !~ 't.*max' → t
'thomas' !~* 'T.*ma' → f
regexp_count | regexp_replace |
regexp_instr | regexp_replace |
regexp_like | regexp_split_to_array |
regexp_match | regexp_split_to_table |
regexp_matches |
regexp_substr |
SELECT '"foo"'::jsonb @> '"foo"'::jsonb;
SELECT '[1, 2, 3]'::jsonb @> '[1, 3]'::jsonb;
SELECT '[1, 2, 3]'::jsonb @> '[3, 1]'::jsonb;
SELECT doc->'site_name' FROM websites
WHERE doc @> '{"tags":[{"term":"paris"}, {"term":"food"}]}';
$.track.segments
: retrieves the
available track segments$.track.segments[*].location
: retrieves
the contents of an array$.track.segments[1].location
: returns
the coordinates of the first segment only? (condition)
: filters$.track.segments[*] ?
(@.location[1] < 13.4).HR ?
(@ > 130)
First filters all segments by location, and then returns high heart rate values for these segments, if available
select name,
medium_hval,
location
from interesting_cities
where (
select ST_Distance (
ST_Transform (location, 3587),
ST_Transform( (
select location
from interesting_cities
where name = 'Boston'), 3587)
) ) < 150000
order by medium_hval
limit 10;
WITH upd AS (
UPDATE employees SET sales_count = sales_count + 1 WHERE id =
(SELECT sales_person FROM accounts WHERE name = 'Acme Corporation')
RETURNING *
)
INSERT INTO employees_log SELECT *, current_timestamp FROM upd;
INSERT INTO distributors (did, dname)
VALUES (5, 'Gizmo Transglobal'), (6, 'Associated Computing, Inc')
ON CONFLICT (did) DO UPDATE SET dname = EXCLUDED.dname;
MERGE INTO wines w
USING wine_stock_changes s
ON s.winename = w.winename
WHEN NOT MATCHED AND s.stock_delta > 0 THEN
INSERT VALUES(s.winename, s.stock_delta)
WHEN MATCHED AND w.stock + s.stock_delta > 0 THEN
UPDATE SET stock = w.stock + s.stock_delta
WHEN MATCHED THEN
DELETE;